﻿using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using SelfService.Model.Interface;
using WalkingTec.Mvvm.Core;

namespace SelfService.Model.Models
{
    public class SysPay : BasePoco, IPay
    {
        [Display(Name = "患者")]
        public SysPatient Patient { get; set; }

        [Display(Name = "患者")]
        [Required]
        public Guid? PatientId { get; set; }

        [Display(Name = "支付方式")]
        public SysPayType PayType { get; set; }

        [Display(Name = "支付方式")]
        [Required]
        public Guid? PayTypeId { get; set; }

        [Display(Name = "支付金额")]
        [Column(TypeName = "decimal(28,6)")]
        [Required]
        [Range(0.01, 999999)]
        public decimal Amount { get; set; }

        [Display(Name = "外部订单号")]
        [StringLength(128)]
        public string OutOrderNo { get; set; }

        [Display(Name = "交易流水号")]
        [StringLength(128)]
        public string SerialsNumber { get; set; }

        [Display(Name = "支付链接")]
        public string PayUrl { get; set; }

        [Display(Name = "支付状态")]
        public PayStatusEnum PayStatus { get; set; }

        [Display(Name = "退款状态")]
        public RefundStatusEnum RefundStatus { get; set; }

        [Display(Name = "支付时间")]
        public DateTime? PayTime { get; set; }

        /// <summary>
        /// 支付用途
        /// </summary>
        [Display(Name = "支付用途")]
        [Required]
        public PayUseEnum Use { get; set; }

        [Display(Name = "使用状态")]
        public UseStatusEnum UseStatus { get; set; }

        [Display(Name = "使用信息")]
        public string UseMessage { get; set; }

        [Display(Name = "创建时间")]
        public new DateTime CreateTime { get; set; }

        [Display(Name = "客户端")]
        public SysClient Client { get; set; }

        [Display(Name = "客户端")]
        public Guid? ClientId { get; set; }

        [Display(Name = "授权码")]
        [StringLength(512)]
        public string AuthCode { get; set; }
        
        [Display(Name = "退款Id")]
        [StringLength(128)]
        public string RefundId { get; set; }
        
        [Display(Name = "退款交易号")]
        [StringLength(128)]
        public string RefundNo { get; set; }

        /// <summary>
        /// 该字段用于将数据同步到旧系统, 正式上线以后可以移除此字段
        /// </summary>
        [Display(Name = "是否同步")]
        public bool IsSync { get; set; }
    }

    public enum PayStatusEnum
    {
        待支付 = 0,
        支付中 = 10,
        支付成功 = 20,
        支付失败 = 30
    }

    public enum RefundStatusEnum
    {
        未发起 = 0,
        退款中 = 10,
        退款完成 = 20,
        退款失败 = 30,
        退款异常= 40
    }

    public enum PayUseEnum
    {
        未知 = 0,
        门诊充值 = 10,
        住院押金充值 = 11,
        挂号 = 12,
        缴费 = 20,
        医保缴费 = 21
    }

    public enum UseStatusEnum
    {
        未知 = 0,
        成功 = 10,
        失败 = 20
    }
}